@extends('layout/index' )
@section('main')
    <div class="mws-panel grid_8">
        <div class="mws-panel-header">
            <span><i class="icon-align-left"></i> 评论列表
            </span>
        </div>
        <div class="mws-panel-body no-padding">
            <div id="DataTables_Table_1_wrapper" class="dataTables_wrapper" role="grid">
                <form action="/Admin/comment/index" method="get">
                    <div class="dataTables_length" id="DataTables_Table_1_length">
                        <label>显示
                            <select aria-controls="DataTables_Table_1" size="1" name="num">
                                <option value="5" {{ (!empty($request['num'])&&$request['num']==5)?'selected':''}}>5</option>
                                <option value="25" {{ (!empty($request['num'])&&$request['num']==25)?'selected':''}}>10</option>
                                <option value="50" {{ (!empty($request['num'])&&$request['num']==50)?'selected':''}}>50</option>
                                <option value="100" {{ (!empty($request['num'])&&$request['num']==100)?'selected':''}}>20</option>
                            </select> 条数据</label>
                    </div>
                    <div id="DataTables_Table_1_filter" class="dataTables_filter">
                        <label>搜索: 
                        <input aria-controls="DataTables_Table_1" type="text" name="search" value="{{$request['num'] or ''}}"></label>
                        <button class="btn btn-default">点击搜索</button>
                    </div>
                </form>
                <table aria-describedby="DataTables_Table_1_info" id="DataTables_Table_1" class="mws-datatable-fn mws-table dataTable">
                    <thead>
                    <tr role="row">
                        <th aria-label="Rendering engine: activate to sort column descending" aria-sort="ascending" style="width: 50px;" colspan="1" rowspan="1" aria-controls="DataTables_Table_1" tabindex="0" role="columnheader" class="sorting_asc">编号</th>
                        <th aria-label="CSS grade: activate to sort column ascending" style="width: 150px;" colspan="1" rowspan="1" aria-controls="DataTables_Table_1" tabindex="0" role="columnheader" class="sorting">商品ID:商品名</th>
                        <th aria-label="Platform(s): activate to sort column ascending" style="width: 150px;" colspan="1" rowspan="1" aria-controls="DataTables_Table_1" tabindex="0" role="columnheader" class="sorting">用户ID:用户名</th>
                        <th aria-label="Engine version: activate to sort column ascending" style="width: 130px;" colspan="1" rowspan="1" aria-controls="DataTables_Table_1" tabindex="0" role="columnheader" class="sorting">商品图片</th>
                        <th aria-label="CSS grade: activate to sort column ascending" style="width: 118px;" colspan="1" rowspan="1" aria-controls="DataTables_Table_1" tabindex="0" role="columnheader" class="sorting">评论内容</th>
                        <th aria-label="CSS grade: activate to sort column ascending" style="width: 118px;" colspan="1" rowspan="1" aria-controls="DataTables_Table_1" tabindex="0" role="columnheader" class="sorting">回复内容</th>
                        <th aria-label="CSS grade: activate to sort column ascending" style="width: 118px;" colspan="1" rowspan="1" aria-controls="DataTables_Table_1" tabindex="0" role="columnheader" class="sorting">评论时间</th>
                        <th aria-label="CSS grade: activate to sort column ascending" style="width: 80px;" colspan="1" rowspan="1" aria-controls="DataTables_Table_1" tabindex="0" role="columnheader" class="sorting">操作</th>
                    </tr>
                      <tbody aria-relevant="all" aria-live="polite" role="alert">
                    @foreach($res as $k=>$v)
                            <tr class="{{$k%2==0?'odd':'even'}}">
                                <td class="  sorting_1">{{$v->id}}</td>
                                <td class=" ">{{$v->gid}}: {{$v->goodsname}}</td>
                                <td class=" ">{{$v->uid}}: {{$v->username}}</td>
                                <td class=" "><img src="{{$v->goodspic}}" alt="" width="60px" height="60px"></td>
                                <td class=" ">{{$v->content}}</td>
                                <td class=" ">{{$v->reply}}</td>
                                <td class=" ">{{$v->posttime}}</td>
                                <td class=" " ><a href="{{URL('/Admin/comment/edit')}}?id={{$v->id}}">修改</a> | <a href="javascript:;" onclick="loadRole({{ $v->id}})">回复</a> | <a href="javascript:;" onclick="return Delete({{$v->id}})">禁用</a></td>
                            </tr>
                    @endforeach
                    </tbody>
                </table>

                <div id="page" class="dataTables_paginate paging_full_numbers">
                        {!! $res->appends($request)->render() !!}
                </div>
            </div>
        </div>
    </div>

    <style type="text/css">

        #loadreply{
            width:400px;
            height:200px;
            background:#444444;
            position:absolute;
            left:300px;
            top:100px;
            z-index:10000;
            display:none;
        }

        #formreplay{
            position:absolute;
            top:36px;
        }

        #quxiao{
            width:60px;
            height:30px;
            color:white;
            line-height:30px;
            text-align:center;
            position:absolute;
            left:340px;
            top:134px;
            font-size:16px;
            cursor:pointer;
            background:#22AC69;  
        }

       #queding{
            width:60px;
            height:30px;
            color:white;
            line-height:30px;
            text-align:center;
            position:absolute;
            left:260px;
            top:134px;
            font-size:16px;
            cursor:pointer;
            background:#22AC69;   
       }
    </style>

    <div id="loadreply" tabindex="-1" role="dialog">
        <div id="formreplay">
            <form action="" id="forms">
                <input type="hidden" name="id" id="replyid" value="">
                <textarea name="reply" id="textarea" cols="46" rows="5" style="resize:none"></textarea>
                {{ csrf_field() }}
            </form>
            <span id="queding">确定</span>
            <span id="quxiao">取消</span>
        </div>
    </div>

@endsection

@section('js')
<script type="text/javascript">
    
    function loadRole(id) {
        $("#loadreply").show();
        $("#replyid").val(id);
    }

    //确定单击事件
    $("#queding").click(function(){
        //表单隐藏
        $("#loadreply").hide();
        //更换回复内容
        //$(".odd").find('td').eq(5).html($("#textarea").val());
        //获取表单所有值
        var forms = $("#forms").serialize();
        //ajax传值
        $.post("/Admin/comment/ajax",forms,function(data){
            
            if(data == "yes") { 
                alert("回复成功");
                location.href="/Admin/comment/index"; 
            } else {
                alert("回复失败");
            }
        })
    })

    //取消单击事件
    $("#quxiao").click(function(){
        $("#loadreply").hide();
    })

    //单击禁用
     function Delete(id){

        if(confirm("确定要禁用吗?")) {
            //发送ajax
            $.get("/Admin/comment/del",{id:id},function(data) {

                 if(data == "yes") {
                     alert("禁用成功");
                     location.href="/Admin/comment/index";
                 } else {
                    alert("禁用失败");
                }
            })
         }
     }
   
</script>

@endsection